﻿using PARK.Common.Const;
using SqlSugar;
using System;
using Yitter.IdGenerator;

namespace PARK.CardAcct.Entitys
{
    /// <summary>
    /// 卡片类型
    /// </summary>
    [SugarTable("base_cardtypes")]
    [Tenant(ClaimConst.TENANT_ID)]
    public class CardtypesEntity
    {
        /// <summary>
        /// 
        /// </summary>
        [SugarColumn(ColumnName = "Id", IsPrimaryKey = true)]
        public string Id { get; set; }

        /// <summary>
        /// CardTypeCode
        /// </summary>
        [SugarColumn(ColumnName = "CardTypeCode")]        
        public string CardTypeCode { get; set; }

        /// <summary>
        /// CardTypeName
        /// </summary>
        [SugarColumn(ColumnName = "CardTypeName")]        
        public string CardTypeName { get; set; }
        
        
        /// <summary>
        /// 状态 1启用 -1停用
        /// </summary>
        [SugarColumn(ColumnName = "EnabledMark")]        
        public int? EnabledMark { get; set; }
        
        /// <summary>
        /// 备注
        /// </summary>
        [SugarColumn(ColumnName = "Description")]        
        public string Description { get; set; }
        
        /// <summary>
        /// 创建人Id
        /// </summary>
        [SugarColumn(ColumnName = "CreatorUserId")]        
        public string CreatorUserId { get; set; }
        
        /// <summary>
        /// 创建人姓名
        /// </summary>
        [SugarColumn(ColumnName = "CreatorUserName")]        
        public string CreatorUserName { get; set; }
        
        /// <summary>
        /// 创建日期
        /// </summary>
        [SugarColumn(ColumnName = "CreatorTime")]        
        public DateTime? CreatorTime { get; set; }

        /// <summary>
        /// LastModifyUserId
        /// </summary>
        [SugarColumn(ColumnName = "LastModifyUserId")]        
        public string LastModifyUserId { get; set; }

        /// <summary>
        /// LastModifyUserName
        /// </summary>
        [SugarColumn(ColumnName = "LastModifyUserName")]        
        public string LastModifyUserName { get; set; }

        /// <summary>
        /// LastModifyTime
        /// </summary>
        [SugarColumn(ColumnName = "LastModifyTime")]        
        public DateTime? LastModifyTime { get; set; }
        
        /// <summary>
        /// 删除标记 1是 0否
        /// </summary>
        [SugarColumn(ColumnName = "IsDeleted")]        
        public int? IsDeleted { get; set; }
        
        /// <summary>
        /// 删除人
        /// </summary>
        [SugarColumn(ColumnName = "DeleteUserId")]        
        public string DeleteUserId { get; set; }
        
        /// <summary>
        /// 删除人姓名
        /// </summary>
        [SugarColumn(ColumnName = "DeleteUserName")]        
        public string DeleteUserName { get; set; }
        
        /// <summary>
        /// 删除时间
        /// </summary>
        [SugarColumn(ColumnName = "DeleteTime")]        
        public DateTime? DeleteTime { get; set; }        
        /// <summary>
        /// 
        /// </summary>
        [SugarColumn(ColumnName = "dbDate")]        
        public DateTime? DbDate { get; set; }

        /// <summary>
        /// 所属公司Id
        /// </summary>
        [SugarColumn(ColumnName = "CompanyId")]
        public string CompanyId { get; set; }

        /// <summary>
        /// 公司名称
        /// </summary>
        [SugarColumn(ColumnName = "CompanyName")]
        public string CompanyName { get; set; }

        /// <summary>
        /// 创建
        /// </summary>
        public virtual void Create()
        {
            var userId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value;
            var userName = App.User.FindFirst(ClaimConst.CLAINM_REALNAME)?.Value;
            this.Id = YitIdHelper.NextId().ToString();
            this.CreatorTime = DateTime.Now;
            this.IsDeleted = 0;           
            if (!string.IsNullOrEmpty(userId))
            {
                this.CreatorUserId = CreatorUserId == null ? userId : CreatorUserId;
                this.CreatorUserName = CreatorUserName == null ? userName : CreatorUserName;
            }
        }

        /// <summary>
        /// 修改
        /// </summary>
        public virtual void LastModify(string Id)
        {
            this.Id = Id;
            var userId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value;
            var userName = App.User.FindFirst(ClaimConst.CLAINM_REALNAME)?.Value;
            this.LastModifyTime = DateTime.Now;
            if (!string.IsNullOrEmpty(userId))
            {
                this.LastModifyUserId = userId;
                this.LastModifyUserName = userName;
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        public virtual void Delete(string Id)
        {
            this.Id = Id;
            var userId = App.User.FindFirst(ClaimConst.CLAINM_USERID)?.Value;
            var userName = App.User.FindFirst(ClaimConst.CLAINM_REALNAME)?.Value;
            this.DeleteTime = DateTime.Now;
            this.IsDeleted = 1;
            if (!string.IsNullOrEmpty(userId))
            {
                this.DeleteUserId = userId;
                this.DeleteUserName = userName;
            }
        }
    }
}